home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995…tember: Reference Library / Dev.CD Sep 95 RL / Dev.CD Sep 95 RL.toast / mac / Technical Documentation / develop / develop Issue 23 code / ProjectDrag 1.1b4 / Sources / ProjectDrag Sources / Update.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-06  |  6.6 KB  |  277 lines  |  [TEXT/MPS ]

  1. /* Update.c: Update applet for ProjectDrag.
  2.  *
  3.  * A set of applets for drag and drop source control by Tim Maroney.
  4.  * See develop, issue 23 for details.
  5.  *
  6.  * Built on DropShell by Leonard Rosenthol, Stephan Somogyi, and Marshall Clow,
  7.  * and using the MoreFiles utilities by Jim Luther.
  8.  *
  9.  * This software is free, but don't modify and redistribute it without
  10.  * changing the status window to indicate your name and your changes!
  11.  */
  12.  
  13.  
  14. #include <Errors.h>
  15.  
  16. #include "DSUserProcs.h"
  17. #include "SourceServer.h"
  18. #include "PDDialogs.h"
  19. #include "MoreFilesExtras.h"
  20. #include "TasksAndErrors.h"
  21.  
  22.  
  23. void UpdateFile(FSSpec *file, Boolean doingFolder);
  24. OSErr UpdateFolder(short vRefNum, long folderID,
  25.                   void (*doFile)(FSSpec *file, Boolean doingFolder));
  26.  
  27.  
  28. /* This routine is called for each file passed in the ODOC event. */
  29.  
  30. pascal void OpenDoc ( FSSpecPtr myFSSPtr, Boolean opening, Handle userDataHandle )
  31. {
  32. #pragma unused ( opening )
  33. #pragma unused ( userDataHandle )
  34.  
  35.     ProcessFileOrFolder(myFSSPtr, UpdateFile, UpdateFolder);
  36. }
  37.  
  38.  
  39. void UpdateFile(FSSpec *file, Boolean doingFolder)
  40. {
  41. #pragma unused ( doingFolder )
  42.  
  43.     Str63 userName;
  44.     Str15 nickname;
  45.     OSErr err;
  46.     CKIDHandle theCKID;
  47.     AEDesc command;
  48.     Str255 projectName;
  49.     
  50.     TaskStart(2001, 1, file->name, NULL, NULL, NULL);
  51.     
  52.     /* find the user name and initials */
  53.     err = GetUserSettings(userName, nickname, false);
  54.     if (err != noErr)
  55.     {
  56.         gDone = true;
  57.         return;
  58.     }
  59.     
  60.     /* get the CKID */
  61.     err = ExtractCKID(file, &theCKID);
  62.     if (err != noErr)
  63.     {
  64.         RaiseErrorString(kProjectDragStrings, kCantGetCKID, file->name,
  65.                          NULL, NULL, NULL);
  66.         return;
  67.     }
  68.     
  69.     /* is the file already checked out or MRO? */
  70.     if ((*theCKID)->modifyReadOnly)
  71.     {
  72.         /* MRO -- orphan & create a CheckOut command for SourceServer
  73.          * OrphanFiles <file>
  74.          * CheckOut -y -d <dir> -project <project> <file>
  75.          */
  76.         
  77.         /* confirm the discard */
  78.         if (!ResTextYesNo(kProjectDragStrings, kConfirmDiscardChanges, file->name, NULL, NULL, NULL))
  79.         {
  80.             DisposeHandle((Handle)theCKID);
  81.             RaiseErrorNumber(userCanceledErr);
  82.             return;
  83.         }
  84.     
  85.         /* mount the project */
  86.         err = MountProjectFromCKID(theCKID, projectName);
  87.         DisposeHandle((Handle)theCKID);
  88.         if (err != noErr) return;
  89.  
  90.         /* orphan the file */
  91.         err = CreateCommand(&command, "OrphanFiles");
  92.         if (err == noErr)
  93.             err = AddFileNameArg(&command, file);
  94.         if (err != noErr)
  95.         {
  96.             AEDisposeDesc(&command);
  97.             RaiseErrorNumber(err);
  98.             return;
  99.         }
  100.         err = SendCommand(&command);
  101.         if (err != noErr) return;
  102.         
  103.         /* create the checkout command */
  104.         err = CreateCommand(&command, "CheckOut");
  105.         if (err == noErr)
  106.             err = AddPStringArg(&command, "\p-y");
  107.         if (err == noErr)
  108.             err = AddDirArg(&command, file->vRefNum, file->parID);
  109.         if (err == noErr)
  110.             err = AddProjectArg(&command, projectName);
  111.         if (err == noErr)
  112.             err = AddPStringArg(&command, file->name);
  113.         if (err != noErr)
  114.         {
  115.             AEDisposeDesc(&command);
  116.             RaiseErrorNumber(err);
  117.             return;
  118.         }
  119.     }
  120.     else if (!(*theCKID)->writeable)
  121.     {
  122.         /* not checked out for modify -- create a CheckOut command for SourceServer
  123.          * CheckOut -d <dir> -project <project> <file>
  124.          */
  125.  
  126.         /* mount the project */
  127.         err = MountProjectFromCKID(theCKID, projectName);
  128.         DisposeHandle((Handle)theCKID);
  129.         if (err != noErr) return;
  130.     
  131.         err = CreateCommand(&command, "CheckOut");
  132.         if (err == noErr)
  133.             err = AddDirArg(&command, file->vRefNum, file->parID);
  134.         if (err == noErr)
  135.             err = AddProjectArg(&command, projectName);
  136.         if (err == noErr)
  137.             err = AddPStringArg(&command, file->name);
  138.         if (err != noErr)
  139.         {
  140.             AEDisposeDesc(&command);
  141.             RaiseErrorNumber(err);
  142.             return;
  143.         }
  144.     }
  145.     else
  146.     {
  147.         /* checked out for modify -- create a CheckOut -cancel command for SourceServer
  148.          * CheckOut -cancel -y -d <dir> -project <project> <file>
  149.          */
  150.         
  151.         /* confirm the cancel */
  152.         if (!ResTextYesNo(kProjectDragStrings, kConfirmDiscardChanges, file->name, NULL, NULL, NULL))
  153.         {
  154.             RaiseErrorNumber(userCanceledErr);
  155.             DisposeHandle((Handle)theCKID);
  156.             return;
  157.         }
  158.         
  159.         /* mount the project */
  160.         err = MountProjectFromCKID(theCKID, projectName);
  161.         DisposeHandle((Handle)theCKID);
  162.         if (err != noErr) return;
  163.  
  164.         err = CreateCommand(&command, "CheckOut");
  165.         if (err == noErr)
  166.             err = AddCStringArg(&command, "-cancel");
  167.         if (err == noErr)
  168.             err = AddCStringArg(&command, "-y");
  169.         if (err == noErr)
  170.             err = AddDirArg(&command, file->vRefNum, file->parID);
  171.         if (err == noErr)
  172.             err = AddProjectArg(&command, projectName);
  173.         if (err == noErr)
  174.             err = AddPStringArg(&command, file->name);
  175.         if (err != noErr)
  176.         {
  177.             AEDisposeDesc(&command);
  178.             RaiseErrorNumber(err);
  179.             return;
  180.         }
  181.     }
  182.     
  183.     /* send the command to SourceServer */
  184.     err = SendCommand(&command);
  185.     if (err == noErr)
  186.         TaskDone();
  187. }
  188.  
  189.  
  190. OSErr UpdateFolder(short vRefNum, long folderID,
  191.                   void (*doFile)(FSSpec *file, Boolean doingFolder))
  192. {
  193. #pragma unused ( doFile )
  194.  
  195.     Str63 userName;
  196.     Str15 nickname;
  197.     OSErr err;
  198.     AEDesc command;
  199.     Str255 projectName;
  200.     
  201.     /* put the folder name in the status window */
  202.     {
  203.         Str31 folderName;
  204.         err = GetDirName(vRefNum, folderID, folderName);
  205.         if (err != noErr) return err;
  206.         TaskStart(2001, 1, folderName, NULL, NULL, NULL);
  207.     }
  208.     
  209.     /* find the user name and initials */
  210.     err = GetUserSettings(userName, nickname, false);
  211.     if (err != noErr)
  212.     {
  213.         gDone = true;
  214.         return err;
  215.     }
  216.     
  217.     /* mount the project */
  218.     err = MountProjectFromFolder(vRefNum, folderID, projectName);
  219.     if (err != noErr) return err;
  220.     
  221.     /* create a CheckOutDir -r command for SourceServer
  222.      * CheckOut -r -project <project> <dir>
  223.      */
  224.     err = CreateCommand(&command, "CheckOutDir");
  225.     if (err == noErr)
  226.         err = AddCStringArg(&command, "-r");
  227.     if (err == noErr)
  228.         err = AddProjectArg(&command, projectName);
  229.     if (err == noErr)
  230.     {
  231.         FSSpec dirSpec;
  232.         dirSpec.vRefNum = vRefNum;
  233.         dirSpec.parID = folderID;
  234.         dirSpec.name[0] = 0;
  235.         err = AddFileNameArg(&command, &dirSpec);
  236.     }
  237.     if (err != noErr)
  238.     {
  239.         AEDisposeDesc(&command);
  240.         return RaiseErrorNumber(err);
  241.     }
  242.     
  243.     /* send the command to SourceServer */
  244.     err = SendCommand(&command);
  245.     if (err != noErr) return err;
  246.     
  247.     /* create a CheckOut -newer -r command for SourceServer
  248.      * CheckOut -newer -r -project <project>
  249.      */
  250.     err = CreateCommand(&command, "CheckOut");
  251.     if (err == noErr)
  252.         err = AddCStringArg(&command, "-newer");
  253.     if (err == noErr)
  254.         err = AddCStringArg(&command, "-r");
  255.     if (err == noErr)
  256.         err = AddProjectArg(&command, projectName);
  257.     if (err != noErr)
  258.     {
  259.         AEDisposeDesc(&command);
  260.         return RaiseErrorNumber(err);
  261.     }
  262.     
  263.     /* send the command to SourceServer */
  264.     err = SendCommand(&command);
  265.     if (err == noErr)
  266.         TaskDone();
  267.     return err;
  268. }
  269.  
  270. void DoFileMenu(short itemID)
  271. {
  272.     if ( itemID == 1 )
  273.         SelectFile();        // call file selection userProc
  274.     else
  275.         SendQuitToSelf();    // send self a 'quit' event
  276. }
  277.